# coding: utf-8

import pytz
from datetime import datetime
import pymongo
from time import time

t0 = time()

tz = pytz.timezone(pytz.country_timezones('cn')[0])
# start = datetime(2014,1,1,0,0,tzinfo=tz)
# end = datetime(2014,12,31,23,59,tzinfo=tz)

log = open('resample_log.txt', 'a')
td = datetime.today()
log.write('#####################################################\n')
log.write('task begins at: ' + td.strftime('%Y-%m-%d %H:%M:%S') + '\n')
log.write('data range:\n')

client = pymongo.MongoClient('121.40.212.219', 27017)  # '121.40.212.219', 27017
db = client.Minute_data

theT = tz.localize(datetime(2017, 6, 29, 9, 0))
endT = tz.localize(datetime(2017, 6, 30, 16, 0))
# db.day.remove({'dateTime': {'$gte': theT, '$lte': endT}, 'symbol': 'IC1606'})
# print("day done")
# db.day.remove({'dateTime': {'$gte': theT, '$lte': endT}, 'volume': 0})
# print("day done")
# db.day.remove({'dateTime': {'$gte': theT, '$lte': endT}})
# print("day done")
# db.one_min_data.remove({'dateTime': {'$gte': theT, '$lte': endT}})
# print("1 done")
# db.one_min_data.remove({'dateTime': {'$gte': theT, '$lte': endT}, 'volume': 0})
# print("1 done volume 0")
db.min_5_data.remove({'dateTime': {'$gte': theT, '$lte': endT}})
print("5 done")
# db.min_15_data.remove({'dateTime': {'$gte': theT, '$lte': endT}, 'volume': 0})
# print("15 done volume=0")
db.min_15_data.remove({'dateTime': {'$gte': theT, '$lte': endT}})
print("15 done")
# db.min_60_data.remove({'dateTime': {'$gte': theT, '$lte': endT}, 'volume': 0})
# db.one_min_data.remove({'symbol': 'bu1809', 'dateTime': {'$gte': theT, '$lte': endT}})
# db.min_5_data.remove({'symbol': 'bu1809', 'dateTime': {'$gte': theT, '$lte': endT}})
# db.min_15_data.remove({'symbol': 'bu1809', 'dateTime': {'$gte': theT, '$lte': endT}})
db.min_30_data.remove({'dateTime': {'$gte': theT, '$lte': endT}})
# db.min_60_data.remove({'symbol': 'pp77777', 'dateTime': {'$gte': theT, '$lte': endT}})
# db.min_120_data.remove({'symbol': 'bu1809', 'dateTime': {'$gte': theT, '$lte': endT}})
# print("60 done volume=0")
# db.min_60_data.remove({'dateTime': {'$gte': theT, '$lte': endT}, 'open': 0})
# print("60 done volume=0")
db.min_60_data.remove({'dateTime': {'$gte': theT, '$lte': endT}})
print("60 done")
db.min_120_data.remove({'dateTime': {'$gte': theT, '$lte': endT}})
print("120 done")
# cur = db.min_5_data.find({}, {'_id': 0, 'symbol': 1})
# db.min_60_data.remove({'symbol': {'$regex': 'pp\d{0,4}$', '$options': 'i'}, 'dateTime': {'$gte': theT, '$lte': endT}})
print 1
